package zencstudio.sgrealtor.adapter;

import java.util.List;

import zencstudio.sgrealtor.model.LoanTermData;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import zencstudio.sgrealtor.R;

public class LoanTermSpinnerAdapter extends ArrayAdapter<LoanTermData>{
	private Context context;
	private List<LoanTermData>pType;
	public LoanTermSpinnerAdapter(Context context, int textViewResourceId,
			List<LoanTermData> objects) {
		super(context, textViewResourceId, objects);
		this.context = context;
		this.pType = objects;
	}

	public int getCount() {
		return pType.size();
	}

	public LoanTermData getItem(int position) {
		return pType.get(position);
	}

	public long getItemId(int position) {
		return position;
	}
	// And the "magic" goes here
    // This is for the "passive" state of the spinner
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // I created a dynamic TextView here, but you can reference your own  custom layout for each spinner item
        TextView label = new TextView(context);
        label.setTextColor(context.getResources().getColor(R.color.OrangeRed));
        // Then you can get the current item using the values array (Users array) and the current position
        // You can NOW reference each method you has created in your bean object (User class)
        label.setText(pType.get(position).toString());

        // And finally return your dynamic (or custom) view for each spinner item
        return label;
    }

    // And here is when the "chooser" is popped up
    // Normally is the same view, but you can customize it if you want
    /*@Override
    public View getDropDownView(int position, View convertView,
            ViewGroup parent) {
        TextView label = new TextView(context);
        label.setTextColor(Color.BLACK);
        label.setText(pType.get(position).getValue());

    	LayoutInflater inflater = 
	              (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		if(convertView == null){
			convertView = inflater.inflate(android.R.layout.simple_spinner_dropdown_item, parent,false);
		}
        return convertView;
    }*/

}
